package com.qing.library_manager.controller.borrow;

import com.qing.library_manager.domain.dto.BorrowDTO;
import com.qing.library_manager.domain.query.BorrowByPageQuery;
import com.qing.library_manager.domain.query.BorrowQuery;
import com.qing.library_manager.domain.query.BorrowUpdateQuery;
import com.qing.library_manager.service.manager.borrow.borrowService;
import com.qing.library_manager.common.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/borrow")
@Api(tags = {"借阅模块"})
public class borrowController{

    private final borrowService borrowService;

    public borrowController(com.qing.library_manager.service.manager.borrow.borrowService borrowService) {
        this.borrowService = borrowService;
    }

    /**
     *  添加借阅信息
     * @param borrowQuery
     * @return
     */
    @ApiOperation("增加借阅图书")
    @PostMapping("/addBorrow")
    public ResponseResult addBorrow(@RequestBody BorrowQuery borrowQuery) {
        return borrowService.addBorrow(borrowQuery);
    }

    /**
     *  删除借阅信息
     * @param borrowShowId
     * @return
     */
    @ApiOperation("删除借阅图书")
    @PostMapping("/deleteBorrow/{borrowShowId}")
    public ResponseResult deleteBorrow(@PathVariable int borrowShowId) {
        return borrowService.deleteBorrow(borrowShowId);
    }

    /**
     *  归还图书
     * @param borrowShowId
     * @return
     */
    @ApiOperation("归还图书")
    @PostMapping("/borrowReturn/{borrowShowId}")
    public ResponseResult borrowReturn(@PathVariable int borrowShowId) {
        return borrowService.borrowReturn(borrowShowId);
    }

    /**
     *  根据特定条件搜索
     * @param readersName
     * @return
     */
    @ApiOperation("根据特定条件搜索")
    @GetMapping("/queryBorrow/{readersName}/{bookName}")
    public ResponseResult queryBorrow(@PathVariable String readersName, @PathVariable String bookName) {
        return borrowService.queryBorrowByName(readersName,bookName);
    }

    /**
     *  更新借阅信息
     * @param borrowUpdateQuery
     * @return
     */
    @ApiOperation("更新借阅信息")
    @PostMapping("/updateBorrowInfo")
    public ResponseResult updateBorrowInfo(@RequestBody BorrowUpdateQuery borrowUpdateQuery) {
        return borrowService.updateBorrowInfo(borrowUpdateQuery);
    }

    /**
     * 分页查询数据
     * @param pageNum
     * @param pageSize
     * @param borrowByPageQuery
     * @return
     */
    @ApiOperation("分页查询数据")
    @PostMapping("/queryBorrowByPage/{pageNum}/{pageSize}")
    public ResponseResult queryBorrowByPage(
            @PathVariable int pageNum,
            @PathVariable int pageSize,
            @RequestBody BorrowByPageQuery borrowByPageQuery) {
        return borrowService.queryBorrowByPage(pageNum,pageSize,borrowByPageQuery);
    }

    /**
     *  根据id查询数据
     * @param borrowShowId
     * @return
     */
    @ApiOperation("根据id查询数据")
    @GetMapping("/queryBorrowById/{borrowShowId}")
    public ResponseResult updateBorrowInfo(@PathVariable int borrowShowId) {
        return borrowService.queryBorrowById(borrowShowId);
    }

    /**
     *  获取全部借阅数据
     * @param
     * @return
     */
    @ApiOperation("获取全部借阅数据")
    @GetMapping("/queryAllBorrow")
    public ResponseResult queryAllBorrow() {
        return borrowService.queryAllBorrow();
    }

}
